package com.example.security.config;/**
 * @Auther: liyipeng
 * @Date: 2020/1/8 12:04
 * @Description:
 */

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>类名: SwaggerConfig</p>
 * <p>描述:TODO</p>
 * <p>创建人: liyp</p>
 * <p>创建时间: 2020/1/8 12:04</p>
 * <p>@version 2.0  </p>
 * <p>修改内容: ......</p>
 * <p>修改说明: ......</p>
 * <p>修改时间: ......</p>
 * <p>修改人: ......</p>
 * <p>每次修改，请增加上述修改信息说明</>
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {

        ParameterBuilder tokenParam = new ParameterBuilder();

        List<Parameter> params = new ArrayList<Parameter>();

        tokenParam.name("Authorization").description("令牌(Bearer Token) (非必须, 输入框默认值为admin用户token)").modelRef(new ModelRef("string")).parameterType("header").required(false)
                .defaultValue("bearer eeb601f2-19e7-4f15-bbc8-b9097f7f051a")
                .build();
        params.add(tokenParam.build());
        ParameterBuilder tokenParam2 = new ParameterBuilder();
        tokenParam2.name("accountId").description("用户id").modelRef(new ModelRef("string")).parameterType("header").required(false)
                .defaultValue("2")
                .build();
        params.add(tokenParam2.build());
        ParameterBuilder tokenParam3 = new ParameterBuilder();
        tokenParam3.name("name").description("测试名字").modelRef(new ModelRef("string")).parameterType("header").required(false)
                .defaultValue("李宜朋")
                .build();
        params.add(tokenParam3.build());

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.example.security")).paths(PathSelectors.any()).build()
                .globalOperationParameters(params);

    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("测试mybatisplus APIs").contact("liyp").version("1.0").build();
    }
}
